package com.roncoo.education.system.service.api.pc.biz;

import com.aliyun.oas.utils.StringUtil;
import com.dingtalk.api.response.OapiDepartmentListResponse;
import com.roncoo.education.system.common.CacheRedis;
import com.roncoo.education.system.common.req.*;
import com.roncoo.education.system.common.resq.MsgPageRESQ;
import com.roncoo.education.system.common.resq.MsgViewRESQ;
import com.roncoo.education.system.feign.vo.MsgPushVO;
import com.roncoo.education.system.service.dao.MsgDao;
import com.roncoo.education.system.service.dao.MsgUserDao;
import com.roncoo.education.system.service.dao.impl.mapper.entity.*;
import com.roncoo.education.system.service.dao.impl.mapper.entity.MsgExample.Criteria;
import com.roncoo.education.system.service.dao.service.impl.mapper.SysDictionariesMapper;
import com.roncoo.education.user.feign.interfaces.IFeignUserExt;
import com.roncoo.education.user.feign.vo.UserExtMsgVO;
import com.roncoo.education.util.base.BaseBiz;
import com.roncoo.education.util.base.Page;
import com.roncoo.education.util.base.PageUtil;
import com.roncoo.education.util.base.Result;
import com.roncoo.education.util.dingd.DingDUtil;
import com.roncoo.education.util.enums.HasNoticeEnum;
import com.roncoo.education.util.enums.RedisPreEnum;
import com.roncoo.education.util.enums.ResultEnum;
import com.roncoo.education.util.enums.StatusIdEnum;
import com.roncoo.education.util.tools.BeanUtil;
import com.roncoo.education.util.tools.Constants;
import com.xiaoleilu.hutool.util.CollectionUtil;
import com.xiaoleilu.hutool.util.ObjectUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 部门信息
 */
@Component
public class PcApidepartmentBiz extends BaseBiz {


	@Autowired
	private DingDUtil dingDUtil;
	@Resource
	private SysDictionariesMapper mapper;


	public Result save()throws Exception{
		String accessToken= dingDUtil.getAccessToken();
		if(StringUtils.isEmpty(accessToken)){
			return Result.error("获取钉钉授权失败");
		}
		OapiDepartmentListResponse response= dingDUtil.getDepartments(accessToken);
		if (null==response.getDepartment()||response.getDepartment().size()<1){
			return Result.error("获取部门信息失败");
		}
		response.getDepartment().forEach(t->{
			SysDepartment dept=new SysDepartment();
			dept.setGmtModified(LocalDateTime.now());
			dept.setParentId(t.getParentid());
			dept.setName(t.getName());
			dept.setId(t.getId());
			dept.insertOrUpdate();
		});

		return Result.success("操作成功");

	}
}
